# -*- coding: utf-8 _*_

# -------------------------------------------------------------------------------
# Name:        Vkuchinator
# Purpose:
#
# Author:      Trubnikov Sergey
#
# Created:     07.06.2014
# Copyright:   (c) Trubnikov Sergey 2014
# Licence:     GPLv2
# -------------------------------------------------------------------------------

#TODO: Create thread

import Vkuchinator
import sys
from PyQt4 import QtCore, QtGui


class MainWindow(QtGui.QWidget):
    def __init__(self, path='', parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.path = path

        self.vbox = QtGui.QVBoxLayout()
        self.hbox_top = QtGui.QHBoxLayout()
        self.hbox_bottom = QtGui.QHBoxLayout()
        self.vbox.addLayout(self.hbox_top)
        self.vbox.addLayout(self.hbox_bottom)

        self.pathDialog = QtGui.QFileDialog()
        self.pathDialog.setFileMode(QtGui.QFileDialog.DirectoryOnly)

        assert isinstance(path, str)
        self.pathEdit = QtGui.QLineEdit(path)
        self.hbox_top.addWidget(self.pathEdit)

        self.browseButton = QtGui.QPushButton(u"Browse...")
        self.hbox_top.addWidget(self.browseButton)
        self.connect(self.browseButton, QtCore.SIGNAL("clicked()"), self.browse)

        self.startButton = QtGui.QPushButton(u"Start")
        self.hbox_bottom.addWidget(self.startButton)
        self.connect(self.startButton, QtCore.SIGNAL("clicked()"), self.start)

        self.exitButton = QtGui.QPushButton(u"Exit")
        self.hbox_bottom.addWidget(self.exitButton)
        self.connect(self.exitButton, QtCore.SIGNAL("clicked()"), self.quit)

        self.setLayout(self.vbox)

    @staticmethod
    def quit():
        sys.exit(0)

    def browse(self):
        self.path = self.pathDialog.getExistingDirectory(self, u"Open Image", self.pathEdit.text())
        self.pathEdit.setText(self.path)
        pass

    def start(self):
        Vkuchinator.main(str(self.pathEdit.text()))


def main(args):
    app = QtGui.QApplication(args)
    path = Vkuchinator.get_path(args)

    main_window = MainWindow(path)
    main_window.setWindowTitle(u"VQtchinator")
    main_window.resize(300, 100)
    main_window.show()

    sys.exit(app.exec_())

if __name__ == '__main__':
    main(sys.argv)
